package com.leijie.zerocopy;

import java.io.DataInputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author LeiJie
 * @time 2020-5-15 16:20
 * @desc 传统的soket io服务端
 */
public class OldIOServer {

    public static void main(String[] args) throws Exception{
        ServerSocket serverSocket = new ServerSocket(8899);

        while (true){
            Socket socket = serverSocket.accept();
            DataInputStream inputStream = new DataInputStream(socket.getInputStream());

            try{
                int totalSize = 0;
                byte[] buffer = new byte[1024];
                while (true){
                    int count = inputStream.read(buffer);
                    if (count == -1){
                        break;
                    }
                    totalSize+=count;
                }
                System.out.println("接收总字节数："+totalSize);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
